<?php
    session_start();
    $cart_arr=isset($_SESSION["cart"])?$_SESSION["cart"]:'';
   /* var_dump($cart_arr);
    die();*/
    if(isset($_GET['cancle'])){
     /*   $key=$_GET['id'];
        unset($cart_arr[$key]);
        $cart_arr = array_values($cart_arr);
        $_SESSION["cart"]=$cart_arr;*/
        unset($_SESSION["cart"]);
        header("Location: products.php");
    }
   require_once('tools.php');
   top_module('Your Cart');
?>
<?php
if(!empty($cart_arr)){
    foreach($cart_arr as $k=>$arr){
        $price = $arr['price'];
        $quantity = $arr['quantity'];
        $id = $arr['id'];
        $name = $arr['name'];
        $option= $arr['option'];
        $picture= $arr['picture'];
        $total_price=$price*$quantity;
        $arr_html= <<<"HTML"
       
      <article>
        <h1></h1>

        <img class="imgfloatLeft" src="$picture" alt="img1">

        
        <form action="" method="POST" onsubmit="return validateForm()">
            <fieldset>
                <legend><em><b>Your Cart</b></em></legend>
                <p id="price">Total Price:$%1.2f </p>
                <br>

                <p id="quantity">Quantity:$quantity</p>
                <br>

                <p id="option">Colour:$option</p>


                <br><br><br>
              
            </fieldset>
        </form>
        </br>




        <br><br>


     </article>
HTML;
        printf($arr_html,$total_price);;
    }

    $button_html=<<<"HTML"
      
      <input type="button" onclick="check_out()" value="Purchase" />

      <button type="button" onclick="cancle($k)">Cancle</button>
HTML;

    echo $button_html;
}



$html = <<<"HTML"
      
      <script>
           function cancle() {
              window.location.href='cart.php?cancle=true';
           } 
           
           function check_out(id) {
              window.location.href="check_out.php";
           }
        
       </script>
    <html>
       <link id='stylecss' type="text/css" rel="stylesheet" href="css/singleProduct.css">

</html>
HTML;
end_module();
echo $html;


?>